
package com.lsh.airticket.service.impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.stereotype.Service;


/**
 * 阿里云短信服务
 */
@Service
public class SendSms {

    public void sendMessage(String messageCode, String phoneNumber) throws ClientException {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                "LTAI4G8BMxnEsh7Vfx8fy2wT", "u2PGRUhPb0lUP8sB9bu0zYhrOtPjW5");
        IAcsClient client = new DefaultAcsClient(profile);
        System.out.println("==============");
        CommonRequest request = new CommonRequest();
        System.out.println("==============");
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        request.putQueryParameter("SignName", "guli在线教育网站");
        request.putQueryParameter("TemplateCode", "SMS_211230294");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + messageCode + "\"}");

        CommonResponse response = client.getCommonResponse(request);
        System.out.println(response.getData());


    }


}